<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
<title>固定资产管理系统</title>
<link type="text/css" href="/static/js/zTree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
<!-- <link rel="stylesheet" href="/static/js/kuCity/kuCity.js"> -->
</head>
<body>
<%@include file="../common/NavigationLeft.jsp"%>
	<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
	<h2 class="page-header"><a href="listAsset.action">返回资产列表</a></h2>
		<form id="addAsset_form" class="form-horizontal" method="post" >
			<input id="assetId"  type="hidden" name="asset.id"  value="${id}"/>
			<div class="form-group">
				<label for="equipIdent_input" class="col-sm-2 control-label">资产编号</label>
				<div class="col-sm-3">
					<input type="text" name="asset.equipIdentifier" class="form-control" id="equipIdent_input"
						placeholder="" value="${asset.equipIdentifier}">
						<!-- <div style="display: none">
				    <p class='col-sm-12' style='color: red'>该资产编号已被使用</p>
			    </div> -->
				</div>
			</div>
			<div class="form-group">
				<label for="it_code_input" class="col-sm-2 control-label">IT编号</label>
				<div class="col-sm-3">
					<input type="text" name="asset.itCode" class="form-control" id="it_code_input"
						   placeholder="" value="${asset.itCode}">
						   <div style="display: none">
				    <p class='col-sm-12' style='color: red'>该IT编号已被使用</p>
			    </div>
				</div>
			</div>
			<div class="form-group">
				<label for="equipModel_input" class="col-sm-2 control-label">设备型号</label>
				<div class="col-sm-3">
					<input type="text" name="asset.equipModel" value="${asset.equipModel}" class="form-control" 
						placeholder="">
				</div>
			</div>
			<div class="form-group">
				<label for="equipBrand_input" class="col-sm-2 control-label">设备品牌</label>
				<div class="col-sm-3">
					<input type="text" name="asset.equipBrand" value="${asset.equipBrand}" class="form-control" 
						placeholder="">
				</div>
			</div>
			<div class="form-group">
				<label for="asset.equipGenre" class="col-sm-2 control-label">设备类别</label>
				<div class="col-sm-3" id="select">
				    <s:select list="#{0:'电子设备',1:'办公设备'}" listKey="key" listValue="value" name="asset.equipGenre"/>
				    设备名称<input type="text" name="asset.equipName" value="${asset.equipName}">
				</div>  				
			</div>
			<%--资产状态   使用中、已分配、维修中、备用、报废--%>
			 <input type="hidden" value="${asset.status}" id="inputStatus">
			<div class="form-group" id="status">			   
				<label for="asset.status" class="col-sm-2 control-label">资产状态</label>
				 <c:if test="${opteStatus == 0}">
                    <div class="col-sm-3">
					<s:select list="#{1:'备用'}" listKey="key" listValue="value" name="asset.status" id="status_select"/>
				    </div>
                 </c:if>
                 
                 <div id="status">
                 <c:if test="${opteStatus == 1}">
                 <div class="col-sm-3">
                      <c:if test="${asset.status == 1 || asset.status == 4 || asset.status == 5}">
                          <s:select list="#{1:'备用',4:'维修中',5:'报废'}" listKey="key" listValue="value" name="asset.status" id="status_select"/>
                      </c:if>
					<%-- <s:select list="#{1:'备用',2:'已分配',3:'使用中',4:'维修中',5:'报废'}" listKey="key" listValue="value" name="asset.status" id="status_select"/> --%>
				</div>
                </c:if>
                </div>
				
			</div>
			<div class="form-group">
				<label for="equipLocation_input" class="col-sm-2 control-label">设备存放地点</label>
				<div class="col-sm-3">
					<input type="text" class="equipLocation" name="asset.equipLocation" value="${asset.equipLocation }">
				</div>
			</div>
        
			<div class="form-group">
				<label for="equipAttach_input" class="col-sm-2 control-label">设备归属地点</label>
				<div class="col-sm-3">
					<input type="text" class="equipAttach" name="asset.equipAttach" value="${asset.equipAttach }">
				</div>
			</div>
			<div class="form-group">
				<label for="useDepart_input" class="col-sm-2 control-label">使用部门</label>
				<div class="col-sm-3">
					 <input id="depart_input" class="form-control" name="asset.useDepart" value="${asset.useDepart }">
                     <button type="button" id="chooseDepartButton">选择部门</button>
				</div>
			</div>
			<%-- <div class="form-group">
				<label for="assetAllocation_input" class="col-sm-2 control-label">资产配置</label>
				<div class="col-sm-3">
					<input type="text" name="asset.assetAllocation" value="${asset.assetAllocation}" class="form-control" id="assetAllocation_input"
						placeholder="">
				</div>
			</div> --%>
			<div class="form-group form-inline">
				<label for="buyTime_input" class="col-sm-2 control-label">购买日期</label>
				<div class="col-sm-3">
					<input  type="text" name="asset.buyTime" onFocus="WdatePicker({el:'buyTime_input',dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" value="<s:date name="asset.buyTime "/>" class="form-control" id="buyTime_input" />
					<img onclick="WdatePicker({el:'buyTime_input',dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" src="/static/js/My97DatePicker/skin/datePicker.gif"
							width="16" height="22" align="absmiddle">
				</div>
			</div>
			<div class="form-group form-inline" id="assign">
				<label for="assignTime_input" class="col-sm-2 control-label">分配日期</label>
				<div class="col-sm-3">
					<input  type="text" name="asset.assignTime" onFocus="WdatePicker({el:'buyTime_input',dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" value="<s:date name="asset.assignTime "/>" class="form-control" id="assignTime_input" />
					<img onclick="WdatePicker({el:'assignTime_input',dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" src="/static/js/My97DatePicker/skin/datePicker.gif"
							width="16" height="22" align="absmiddle">
				</div>
			</div>
			 <div class="form-group form-inline" id="receive">
				<label for="reveiveTime_input" class="col-sm-2 control-label">领用日期</label>
				<div class="col-sm-3">
					<input  type="text" name="asset.receiveTime" onFocus="WdatePicker({el:'buyTime_input',dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" value="<s:date name="asset.receiveTime " />" class="form-control" id="receiveTime_input" />
					<img onclick="WdatePicker({el:'receiveTime_input',dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" src="/static/js/My97DatePicker/skin/datePicker.gif"
							width="16" height="22" align="absmiddle">
				</div>
			</div>	
			<div class="form-group form-inline" id="revert">
				<label for="reveiveTime_input" class="col-sm-2 control-label">归还日期</label>
				<div class="col-sm-3">
					<input  type="text" name="assetUseHistory.revertTime" onFocus="WdatePicker({el:'buyTime_input',dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" value="<s:date name="assetUseHistory.revertTime " />" class="form-control" id="revertTime_input" />
					<img onclick="WdatePicker({el:'revertTime_input',dateFmt:'yyyy-MM-dd HH:mm:ss',maxDate:'%y-%M-%d'})" src="/static/js/My97DatePicker/skin/datePicker.gif"
							width="16" height="22" align="absmiddle">	    
				</div>
				<label for="optestate_input" class="col-sm-2 control-label" ><span style="color: red">* </span>请选择设备状态</label>
				<div class="col-sm-3">  	 
	                <s:select list="#{0:'-请选择-',1:'良好',2:'损坏,需维修',3:'损坏,已报废'}" listKey="key" listValue="value" id="optestate" name="assetUseHistory.equipState"/>	    
				</div>
			</div>
			<div class="form-group">
				<label for="remark" class="col-sm-2 control-label">备注</label>
				<div class="col-sm-3">
					<textarea  name="asset.remarks" class="form-control" id="remark">${asset.remarks}</textarea>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button id="submit_btn" type="submit"  class="btn btn-default">提交</button>
				</div>
			</div>			
		</form>
		 <div class="layer_panel" id="select_department_panel" >
        <div>
            <ul id="treeDemo" class="ztree"></ul>
        </div>
    </div>
	</div>
<!-- <script src="/static/js/kuCity/kuCity.js"></script>
<script src="http://www.jq22.com/jquery/jquery-1.9.1.js"></script> -->

<script type="text/javascript" src="/static/js/zTree/js/jquery.ztree.core.js"></script>

<script type="text/javascript">

//存放,归属地点
$(".equipLocation").kuCity();
$(".equipAttach").kuCity();
var zTreeObj;
// zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
var setting = {
    callback:{
        onClick:function (event, treeId, treeNode) {
            var nodes = treeNode.getPath();
            var path = "";
            for(var index in nodes){
                path = path+"/"+nodes[index].name;
            }
            path = path.substr(1);
            $("#depart_require_msg").html("");
            $("#depart_input").val(path);
        }
    },

};

$("#depart_input").focus(function () {
    layer.open({
        title: '选择部门',
        type: 1,
        area: ['400px'],
        content: $("#select_department_panel"),
        btn: ['确定', '取消'],
        yes: function(index, layero) {
            layer.close(index);
        },
        cancel: function(index) {}
    });
})


$("#chooseDepartButton").click(function(){
    layer.open({
        title: '选择部门',
        type: 1,
        area: ['400px'],
        content: $("#select_department_panel"),
        btn: ['确定', '取消'],
        yes: function(index, layero) {
            layer.close(index);
        },
        cancel: function(index) {}
    });
});    


$(function () {
    var departments;
    $("#departDiv-0").find("select").change();
    initSelectDepart();
    function initSelectDepart() {
        $.ajax({
            url:"/asset/listDepartments.action",
            type:"post",
            data:{departQueryName:'CTO中心'},
            success:function (data) {
//                departments = data;
                zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, data);
            }
        })
    }
})
 $(function(){
	var inputStatus = $("#inputStatus").val();
	if(inputStatus == 2 || inputStatus == 3){
		 $("#status").hide();
	}
});

 /* $("#equipIdent_input").change(function(){
    	var equipIdentifier = $("#equipIdent_input").val();
    	$.ajax({
    		 type : 'POST',
             url : 'ajax_ListUserDataCheck.action',
             data : {"equipIdentifier":equipIdentifier},
             success : function(result) {
            	 if(result.operaRes == "1"){
            		 $("#equipIdent_input").next().show();
            	 }else{
            		 $("#equipIdent_input").next().hide();
            	 }            	                                           
             }
    	});
    });
    
      $("#it_code_input").change(function(){
    	var itCode = $("#it_code_input").val();
    	$.ajax({
    		 type : 'POST',
             url : 'ajax_ListUserDataCheck.action',
             data : {"itCode":itCode},
             success : function(result) {
            	 if(result.operaRes == "1"){
            		 $("#it_code_input").next().show();
            	 }else{
            		 $("#it_code_input").next().hide();
            	 }            	                                           
             }
    	});
    });  */

     
 $(function(){
    	$("#assign").hide();    	
    	var receiveTime = $("#receiveTime_input").val();
    	if(receiveTime == ""){
    		$("#receive").hide();
    	}
    	var revertTime = $("#revertTime_input").val();
    	if(revertTime == ""){
    		$("#revert").hide();
    	}else{
    		$("#receive").hide();
    	}
    });
    //插件，指定输入框不能为空required
    $('#addAsset_form').validator({
      
    	rules: { 
    		equipIdentifierRemote:function() {
    			
                   return $.ajax({
                	   url: "ajax_ListUserDataCheck.action",  //后台处理程序
                       type: "POST", //数据发送方式
                       data: {  //要传递的数据
                        	"equipIdentifier": function() {
                               return $("#equipIdent_input").val();                       
                           }
                       },
                       dataFilter: function (data) {//判断控制器返回的内容
                                return null;                         
                      } 
                   }  ) 
                },
          	  itCodeRemote:function() {
        			
                  return $.ajax({
               	   url: "ajax_ListUserDataCheck.action",  //后台处理程序
                      type: "POST", //数据发送方式
                      data: {  //要传递的数据
                           "itCode": function(){
                       	   return $("#it_code_input").val();
                          }
                      },
                      dataFilter: function (data) {//判断控制器返回的内容
                               return null;                         
                     } 
                  }  ) 
               }
          },
        	fields:{
              	"asset.equipIdentifier":"required;equipIdentifierRemote",
              	"asset.itCode":"required;itCodeRemote",
          		"asset.equipModel":"required",   
            },

        valid: function(form) {
            var me = this;
            var id = $("#assetId").val();
            var optestate = $("#optestate").val();//此处拿到的是listKey值
            var receiveTime = $("#receiveTime_input").val();
            var revertTime = $("#revertTime_input").val();
            //在提交表单之前，保持表单，防止重复提交
            me.holdSubmit();
            var url = "";
            if (id == '0') {
                url = "ajax_addAsset.action";
            }  else {
                url = "ajax_modifyAsset.action?id="+id+"&&optestate="+optestate+"&&receiveTime="+receiveTime+"&&revertTime="+revertTime;
            } 
            $.ajax({
                url: url,
                data: $(form).serialize(),        
                type: "POST",
                success: function(result){
                    // 表单提交成功之后，释放保持,此处的提交页面并未跳转，需要在下面进行跳转
                    if(result.operaRes == "1"){
                    	 me.holdSubmit(false); 
                    	 location.href="/asset/listAsset.action";
                    }else{
                    	 layer.msg("操作失败");
                    }
                },
                error: function(){                   	
                    layer.msg("操作失败，服务器错误");             	               	       
                }
            });                   
        }
    });   
</script>
</body>

</html>